<?php echo $this->render('/public/header'); ?>
    <script src="https://cdn.bootcss.com/echarts/3.8.5/echarts.min.js"></script>
<?php use yii\helpers\Url; ?>
    <div id="main" class="col-xs-12">
        <div class="form-inline">
            <form method="get">
                <div class="form-group">
                    <select class="form-control" name="bank">
                        <option value=0>银行分类</option>
                        <?php foreach (yii::$app->params['bank'] as $k => $v): ?>
                            <option value="<?php echo $k; ?>" <?php echo yii::$app->request->get("bank") == $k ? 'selected' : ""; ?>><?php echo $v; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>

                <div class="form-group">
                    <input placeholder="起始时间" style="width:150px"
                           value="<?php echo yii::$app->request->get('begin_time'); ?>" type="text" name="begin_time"
                           class="layui-input" onclick="layui.laydate({elem: this})">
                </div>

                <div class="form-group">
                    <input placeholder="结束时间" style="width:150px" type="text" name="end_time" class="layui-input"
                           value="<?php echo yii::$app->request->get('end_time'); ?>"
                           onclick="layui.laydate({elem: this})">
                </div>

                <div class="form-group">
                    <input type="text" style="width:150px" name="invocie" class="form-control"
                           value="<?php echo yii::$app->request->get('invocie'); ?>" placeholder="搜索invocie编号">
                </div>

                <div class="form-group">
                    <input type="text" style="width:150px" name="number" class="form-control"
                           value="<?php echo yii::$app->request->get('number'); ?>" placeholder="搜索客户编号">
                </div>

                <div class="form-group">
                    <input type="text" style="width:150px" name="customer_name" class="form-control"
                           value="<?php echo yii::$app->request->get('customer_name'); ?>" placeholder="搜索客户名字">
                </div>

                <div class="form-group">
                    <select name="type" class="form-control" v-model="bank_type_selected" style="width:100px">
                        <option value=0>--收支类型选择--</option>
                        <option v-for="(v,k) in bank_type" :value="v.id">{{v.name}}</option>
                    </select>
                </div>

                <div class="form-group">
                    <input type="number" style="width:100px" class="form-control" name="money"
                           value="<?php echo yii::$app->request->get('money'); ?>" step="0.01" placeholder="金额搜索">
                </div>

                <div class="form-group">
                    <select name="service_name" class="form-control" v-model="staff_selected" style="width:100px">
                        <option value=0>--业务员--</option>
                        <option v-for="v in staff_list" :value="v.job_number">{{v.name}}</option>
                    </select>
                </div>

                <div class="form-group">
                    <input type="text" style="width:100px" placeholder="产品搜索" class="form-control" name="product"
                           value="<?php echo yii::$app->request->get('product'); ?>" step="0.01" placeholder="金额搜索">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="搜索采购编号" name="purchase_num"
                           value="<?php echo yii::$app->request->get('product_num'); ?>">
                </div>
                <div class="form-group">
                    <select class="form-control" name="group" v-model='group_selected'>
                        <option value="0">--全部--</option>
                        <option v-for="v in group_list" :value="v.id">{{v.group_name}}</option>
                    </select>
                </div>

                <button class="btn btn-success btn-small" style="margin-left: 5px">搜索</button>
                <div class="alert alert-info" style="float:right;marign-left:10px">
                    累计支出:
                    <?php echo $this->params['caculate_num']['out_money']; ?> </div>
                <div class="alert alert-danger" style="float:right;marign-left:10px">
                    累计收入:
                    <?php echo $this->params['caculate_num']['in_money']; ?> </div>
            </form>

        </div>
        <br/>
        <button class="btn btn-danger" @click="showchart">显示图表</button>
        <div v-show="!show">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th style="width:40px">id</th>
                    <th style="width:80px">银行类别</th>
                    <th style="width:80px">日期</th>
                    <th style="width:50px">是否拆分</th>
                    <th>转入金额</th>
                    <th style="width:80px">转出金额</th>
                    <th style="width:90px">余额</th>
                    <th style="width:50px">国家</th>
                    <th style="width:80px">客户编号</th>
                    <th style="width:110px">客户名称</th>
                    <th style="width:80px">业务员</th>
                    <th style="width:100px">性质</th>
                    <!-- <th style="width:80px">性质子类</th> -->
                    <th style="width:150px">产品</th>
                    <th style="width:150px">账号</th>
                    <th>采购</th>
                    <th style="width:100px">invocie编号</th>
                    <th style="width:100px">采购编号</th>
                    <th>部门</th>
                    <th style="width:100px">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($this->params['list'] as $k => $v) { ?>
                    <tr>
                        <td>
                            <?php echo $v['id']; ?>
                        </td>
                        <td style="padding:0px">
                            <select style="border:none;padding: 0px;width:100%"
                                    onchange="change_bank_bill(<?php echo $v['id']; ?>,'bank',this)">
                                <option value=0>请选择</option>
                                <?php foreach (yii::$app->params['bank'] as $k2 => $v2): ?>
                                    <option value="<?php echo $k2; ?>" <?php echo $v['bank'] == $k2 ? 'selected' : ""; ?>><?php echo $v2; ?></option>
                                <?php endforeach; ?>
                            </select>
                        </td>
                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'date',this)"
                                   style="border:none;padding: 0px;width:100%" value="<?php echo $v['date']; ?>"/>
                        </td>
                        <td><?php echo $v['pid'] != $v['id'] ? '拆分项'.$v['pid'] : ''; ?></td>
                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'in_money',this)"
                                   style="border:none;padding: 0px;width:100%;<?php echo !$v['moneySame'] ? 'color:red' : ''; ?>"
                                   value="<?php echo $v['in_money']; ?>"/>
                        </td>

                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'out_money',this)"
                                   style="border:none;padding: 0px;width:100%;<?php echo !$v['moneySame'] ? 'color:red' : ''; ?>"
                                   value="<?php echo $v['out_money']; ?>"/>
                        </td>

                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'remain_money',this)"
                                   style="border:none;padding: 0px;width:100%"
                                   value="<?php echo $v['remain_money']; ?>"/>
                        </td>

                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'country',this)"
                                   style="border:none;padding: 0px;width:100%" value="<?php echo $v['country']; ?>"/>
                        </td>
                        <td>

                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'number',this)"
                                   style="border:none;padding: 0px;width:100%;<?php echo $v['same'] ? '' : 'color:red'; ?>"
                                   value="<?php echo $v['number']; ?>"/>
                        </td>
                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'customer_name',this)"
                                   style="border:none;padding: 0px;width:100%;<?php echo $v['same'] ? '' : 'color:red'; ?>"
                                   value="<?php echo $v['customer_name']; ?>"/>
                        </td>

                        <td>
                            <select onchange="change_bank_bill(<?php echo $v['id']; ?>,'service_name',this)"
                                    style="border:none;padding: 0px;width:100%">
                                >
                                <option value=0>请选择</option>
                                <?php foreach ($this->params['saleman_list'] as $k2 => $v2) { ?>
                                    <option value="<?php echo $v2['job_number']; ?>" <?php if ($v['service_name'] == $v2['job_number']) {
                                        echo 'selected';
                                    } ?>><?php echo $v2['name']; ?></option>
                                <?php } ?>
                            </select>

                        </td>

                        <td>
                            <select id="type" style="border:none;padding: 0px;width:100%"
                                    onchange="change_bank_bill(<?php echo $v['id']; ?>,'type',this)">
                                <option value=0>--请选择--</option>
                                <?php foreach ($this->params['bank_type'] as $va) :
                                    ?><
                                    <option value="<?php echo $va['id']; ?>" <?php if ($v['type'] == $va['id']) {
                                        echo 'selected';
                                    } ?>><?php echo $va['name']; ?></option>
                                <?php endforeach; ?>
                            </select>
                        </td>
                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'product',this)"
                                   style="border:none;padding: 0px;width:100%" value="<?php echo $v['product']; ?>"/>
                        </td>
                        <td>

                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'account',this)"
                                   style="border:none;padding: 0px;width:100%" value="<?php echo $v['account']; ?>"/>
                        </td>

                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'buyer',this)"
                                   style="border:none;padding: 0px;width:100%" value="<?php echo $v['buyer']; ?>"/>
                        </td>

                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'invocie_num',this)"
                                   style="border:none;padding: 0px;width:100%"
                                   value="<?php echo $v['invocie_num']; ?>"/>

                        </td>

                        <td>
                            <input onchange="change_bank_bill(<?php echo $v['id']; ?>,'purchase_num',this)"
                                   style="border:none;padding: 0px;width:100%"
                                   value="<?php echo $v['purchase_num']; ?>"/>
                        </td>

                        <td>
                            <select onchange="change_bank_bill(<?php echo $v['group']; ?>,'group',this)"
                                    style="border:none;padding: 0px;width:100%">
                                <?php foreach ($this->params['group_list'] as $k2 => $v2) : ?>
                                    <option value="<?php echo $v2['id']; ?>" <?php if ($v['group'] == $v2['id']) {
                                        echo 'selected';
                                    } ?>><?php echo $v2['group_name']; ?></option>
                                <?php endforeach ?>
                            </select>
                        </td>

                        <td>
                            <button @click="splitBank(<?php echo $v['id']; ?>)"
                                    class="layui-btn layui-btn-mini layui-btn-normal">拆分
                            </button>
                            <a class="layui-btn layui-btn-mini layui-btn-danger" href="javascript:void(0)"
                               onclick="del_bank_bill(<?php echo $v['id']; ?>)">删除</a>
                        </td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
            <div id="page" style="display: inline-block;"></div>
            <div style="display: inline-block;line-height: 55px">共
                <?php echo $this->params['pagecount']; ?>条记录
            </div>
        </div>
        <div v-show="show" ref="chart" style="width:1200px;height:700px"></div>
    </div>
    <script>
        var vm = new Vue({
            el: "#main",
            data: {
                bank_type_selected: <?php echo yii::$app->request->get('type') ?? 0;?>,
                bank_type: <?php echo json_encode($this->params['bank_type']);?>,
                staff_selected: <?php echo yii::$app->request->get("service_name") ?? 0;?>,
                staff_list: <?php echo json_encode($this->params['saleman_list']);?>,
                group_selected: <?php echo yii::$app->request->get('group') ?? 0;?>,
                group_list: <?php echo json_encode($this->params['group_list']);?>,
                show: false
            },
            mounted: function () {
                var myChart = echarts.init(this.$refs.chart);
                // 指定图表的配置项和数据
                option = {
                    color: ['#3398DB'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            data: <?php echo json_encode($title);?>,
                            axisTick: {
                                alignWithLabel: true
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    series: [
                        {
                            name: '直接访问',
                            type: 'bar',
                            barWidth: '60%',
                            data:<?php echo json_encode($chart);?>
                        }
                    ]
                };


                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
                this.chart = myChart;
            },
            methods: {
                splitBank: function (id) {
                    layer.confirm('确认拆分', {}, function () {
                        $.post('/table/split-bank', {id: id}, function (res) {
                            layer.alert(res.msg);
                            if (res.code == 1) {
                                setTimeout(function () {
                                    window.location.realod();
                                }, 1000)
                            }
                        }, 'json')
                    })
                },
                showchart: function () {
                    if (this.show == true) {
                        this.show = false;
                    } else {
                        this.show = true;
                    }
                    console.log(this.chart);
                    this.chart.resize();
                }
            }
        });

        function del_bank_bill(v) {
            if (layer.confirm('确认删除', {}, function () {
                    var url = "<?php echo Url::to(['table/del_bank']);?>";
                    $.post(url, {
                        id: v
                    }, function (res) {
                        if (res.code == 1) {
                            layer.confirm(res.msg, {}, function () {
                                window.location.reload();
                            })
                        } else {
                            layer.alert(res.msg);
                        }
                    }, 'json')
                })) ;
        }

        layui.laypage({
            cont: 'page',
            pages: <?php echo $this->params['page']['page'];?>,
            curr: <?php echo $this->params['page']['curr'];?>,
            skin: '#5FB878',
            skip: true,
            jump: function (obj, first) {
                if (!first) {
                    if (window.location.search) {
                        window.location.href = "<?php echo $this->params['page']['base_url'];?>&p=" + obj.curr;
                    } else {
                        window.location.href = "<?php echo $this->params['page']['base_url'];?>?p=" + obj.curr;
                    }

                }
            }
        });

        function change_bank_bill(id, column, e) {
            if (layer.confirm('确认修改', {}, function () {
                    var url = "<?php echo Url::to(['table/bank_edit_by_column']);?>";
                    var data = {
                        id: id,
                        column: column,
                        v: e.value
                    };
                    $.post(url, data, function (res) {
                        layer.alert(res.msg);
                    }, 'json')
                })) ;
        }
    </script>
<?php echo $this->render('/public/footer'); ?>